﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinkCard.AdminCP.Common;
using System.Data;
using System.Data.SqlClient;

namespace LinkCard.ShopCP.Sell
{
    public partial class trading_history : System.Web.UI.Page

    {
        private int _totalRecords;

        private int nPageSize = 20;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                

                if (Request.QueryString["CardNumber"] !=null)
                {
                    string sCardNumber = Request.QueryString["CardNumber"].ToString();
                    string sFilter = "AND CardNumber='" + sCardNumber + "'";
                    DataBindPaging(sFilter);

                    getCusInfo(sFilter);
                }
            }
        }
        private void getCusInfo(string sFilter) {
            string sSQL = "Select CardNumber, Point, FullName from Customer where 1=1 " + sFilter;
            DataTable dt = DataHelper.SelectTable(sSQL, false);
            if (dt.Rows.Count > 0) { 
                CardNumber.Text = dt.Rows[0]["CardNumber"].ToString();
                Point.Text = Utility.sInt(ConvertUtility.ToInt32( dt.Rows[0]["Point"].ToString()));
                CustomerName.Text = dt.Rows[0]["FullName"].ToString();
            }
        
        }
        private void DataBindPaging( string sFilter)
        {

            try
            {
                

                int curpage = 0;

                if (Request.QueryString["page"] != null)
                {
                    curpage = Convert.ToInt32(Request.QueryString["page"]);
                }
                else
                {
                    curpage = 1;
                }

                DataTable dt = DataHelper.LoadPageInSQL("TradingHistory", curpage, nPageSize, ref _totalRecords, new SqlParameter("@Filter", sFilter));

                if (dt.Rows.Count > 0)
                {
                    int nPageCount;

                    if (_totalRecords % nPageSize == 0)
                    {
                        nPageCount = _totalRecords / nPageSize;
                    }
                    else
                    {
                        nPageCount = Convert.ToInt32(_totalRecords / nPageSize) + 1;
                    }

                    if (nPageCount < 2) divPager.Visible = false;

                    PagerShow.Text = hash1way.ShowPageNavigation(curpage, nPageCount);

                    msgList.DataSource = dt;

                    msgList.DataBind();
                    msgNoData.Visible = false;

                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
    }
}